package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.exception.base.BaseException;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDTO;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.CountByTimeVO;
import com.zzyl.nursing.vo.ReservationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 *
 * @author mr.luo
 * @date 2025-05-24
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class ReservationController extends BaseController {
    @Autowired
    private IReservationService reservationService;

    /**
     * 2.1 查询当天取消预约数量
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public AjaxResult selectCancel() {
        Integer count = reservationService.selectCancel();
        return success(count);
    }

    /**
     * 2.2 查询每个时间段剩余预约次数
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public AjaxResult countByTime(Long time) {
        List<CountByTimeVO> list = reservationService.countByTime(time);
        return success(list);
    }

    /**
     * 新增预约
     */
    @PostMapping
    @ApiOperation(value = "新增预约")
    public AjaxResult add(@ApiParam(value = "预约信息实体", required = true) @RequestBody Reservation reservation) {
        reservationService.add(reservation);
        return success();
    }

    /**
     * 2.4 分页查询预约
     */
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public AjaxResult page(ReservationDTO dto) {
        startPage();
        List<ReservationVO> list = reservationService.selectPageList(dto);
        return success(getDataTable(list));
    }

    /**
     * 取消预约
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult cancel(@ApiParam(value = "预约信息ID", required = true) @PathVariable("id") Long id) {
        Reservation byId = reservationService.getById(id);
        if (byId == null) {
            throw new BaseException("预约信息不存在！");
        }
        if (byId.getStatus() < 2) {
            byId.setStatus(2);
            reservationService.updateById(byId);
        }
        return success();
    }


//    /**
//     * 查询预约信息列表
//     */
//    @PreAuthorize("@ss.hasPermi('nursing:reservation:list')")
//    @GetMapping("/list")
//    @ApiOperation(value = "获取预约信息列表")
//    public TableDataInfo<List<Reservation>> list(Reservation reservation) {
//        startPage();
//        List<Reservation> list = reservationService.selectReservationList(reservation);
//        return getDataTable(list);
//    }
//
//    /**
//     * 导出预约信息列表
//     */
//    @PreAuthorize("@ss.hasPermi('nursing:reservation:export')")
//    @Log(title = "预约信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ApiOperation("导出预约信息列表")
//    public void export(HttpServletResponse response, Reservation reservation) {
//        List<Reservation> list = reservationService.selectReservationList(reservation);
//        ExcelUtil<Reservation> util = new ExcelUtil<Reservation>(Reservation.class);
//        util.exportExcel(response, list, "预约信息数据");
//    }
//
//    /**
//     * 获取预约信息详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('nursing:reservation:query')")
//    @GetMapping(value = "/{id}")
//    @ApiOperation("获取预约信息详细信息")
//    public R<Reservation> getInfo(@ApiParam(value = "预约信息ID", required = true)
//                                  @PathVariable("id") Long id) {
//        return R.ok(reservationService.selectReservationById(id));
//    }
//
//    /**
//     * 新增预约信息
//     */
//    @PreAuthorize("@ss.hasPermi('nursing:reservation:add')")
//    @Log(title = "预约信息", businessType = BusinessType.INSERT)
//    @PostMapping
//    @ApiOperation("新增预约信息")
//    public AjaxResult add(@ApiParam(value = "预约信息实体", required = true) @RequestBody Reservation reservation) {
//        return toAjax(reservationService.insertReservation(reservation));
//    }
//
//    /**
//     * 修改预约信息
//     */
//    @PreAuthorize("@ss.hasPermi('nursing:reservation:edit')")
//    @Log(title = "预约信息", businessType = BusinessType.UPDATE)
//    @PutMapping
//    @ApiOperation("修改预约信息")
//    public AjaxResult edit(@ApiParam(value = "预约信息实体", required = true) @RequestBody Reservation reservation) {
//        return toAjax(reservationService.updateReservation(reservation));
//    }
//
//    /**
//     * 删除预约信息
//     */
//    @PreAuthorize("@ss.hasPermi('nursing:reservation:remove')")
//    @Log(title = "预约信息", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    @ApiOperation("删除预约信息")
//    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组") @PathVariable Long[] ids) {
//        return toAjax(reservationService.deleteReservationByIds(ids));
//    }


}
